package com.badibadi.mail;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.activity.BaseActivity;
import com.badibadi.infos.PayUserContactShow1Model;
import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

//问方不满意答方的回答，填写不满意原因 activity_mail_content
public class MailbumanyiActivity extends BaseActivity {

	PayUserContactShow1Model payUserContactShow1Model;

	EditText activity_mail_content;
	boolean is_firstbumanyi;
	String reply_id;
	public Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(MailbumanyiActivity.this);
				try {
					Utils.showMessage(MailbumanyiActivity.this, getResources()
							.getString(R.string.l_net_error));
				} catch (Exception e) {
				}
				break;
			case 2:// 设定成功
				Utils.ExitPrgress(MailbumanyiActivity.this);
				try {
					// initListView();
					// initView();
					Utils.showMessage(MailbumanyiActivity.this, getResources()
							.getString(R.string.wx_send_success));
					// Intent intent=new
					// Intent(MailbumanyiActivity.this,Mail67Activity.class);
					// //
					// payUserContactShow1Model.getZhannei_usercontact().get(0).setIs_fee("1");
					// payUserContactShow1Model.getZhannei_usercontact().get(0).setFees(feiyong);
					// intent.putExtra("payUserContactShow1Model",
					// payUserContactShow1Model);
					// startActivity(intent);
					finish();

				} catch (Exception e) {
				}
				break;
			case 3:
				Utils.ExitPrgress(MailbumanyiActivity.this);
				try {
					Utils.showMessage(MailbumanyiActivity.this, getResources()
							.getString(R.string.l_xb12));
				} catch (Exception e) {
				}
				break;
			case 4:// 系统错误
				Utils.ExitPrgress(MailbumanyiActivity.this);
				try {
					Utils.showMessage(MailbumanyiActivity.this, getResources()
							.getString(R.string.wx_send_false));
				} catch (Exception e) {
				}
				break;

			}
		}

	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.activity_mailbumanyi);

		is_firstbumanyi = getIntent().getBooleanExtra("mail", false);
		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		payUserContactShow1Model = (PayUserContactShow1Model) getIntent()
				.getSerializableExtra("payUserContactShow1Model");

		reply_id = payUserContactShow1Model.getZhannei_usercontact().get(0)
				.getThisMsgId();
		// 收件方
		TextView shoujianfang = (TextView) this.findViewById(R.id.shoujianfang);
		shoujianfang.setText(""
				+ payUserContactShow1Model.getSender().getNickName());
		activity_mail_content = (EditText) this
				.findViewById(R.id.activity_mail_content);
//		   
//				"MailbumanyiActivity"
//						+ payUserContactShow1Model
//								.getZhannei_usercontact()
//								.get(payUserContactShow1Model
//										.getZhannei_usercontact().size() - 1)
//								.getThisMsgId());
		// 主旨
		TextView et_zhuzhi = (TextView) this.findViewById(R.id.et_zhuzhi);
		if (payUserContactShow1Model.getZhannei_usercontact().get(0).getTitle()
				.indexOf(getResources().getString(R.string.wx_reply_kuohao)) == 0) {
			et_zhuzhi.setText(""
					+ payUserContactShow1Model.getZhannei_usercontact().get(0)
							.getTitle());
		} else {
			et_zhuzhi.setText(getResources()
					.getString(R.string.wx_reply_kuohao)
					+ payUserContactShow1Model.getZhannei_usercontact().get(0)
							.getTitle());
		}
		// 发送
		this.findViewById(R.id.activity_mail_send).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (activity_mail_content.getText().toString()
								.equals("")) {
							Utils.showMessage(MailbumanyiActivity.this,
									getResources()
											.getString(R.string.wx_txt_87));
						} else {
							displeased();
						}

					}
				});
	}

	/*
	 * 有咨询费时，问方对答方的回答不满意操作（两次不满意调用接口）----POST
	 * 
	 * @param $zhaneniId 站内信ID
	 * 
	 * @param $uid 登录用户（问方）
	 * 
	 * @param $reply_id 回复的是哪一条用户消息ID
	 * 
	 * @param $dissatisfied_reason 问方不满意原因
	 */
	public void displeased() {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
		map.put("uid", Utils.getUid(MailbumanyiActivity.this));
		map.put("reply_id", reply_id);
		map.put("dissatisfied_reason", activity_mail_content.getText()
				.toString());
		CommonUtils.CommomPostfunction(MailbumanyiActivity.this,
				Constants.BadiUrl_1 + "/" + "inform/displeased", map, handler,
				1, 3, 2, 4);
	}

}
